//
//  CultureNetService.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/20.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "CultureNetService.h"
#import "GFXNetworkHandle.h"
#import "MenuListModel.h"
#import "ArticleListModel.h"

NSString * const CulturemenuUrl = @"red/culture/list/category";//商城搜索
NSString * const ArticleListsUrl = @"red/culture/get/by/categoryId";//文章列表
NSString * const ArticleDetailUrl = @"red/culture/get/by/id";//文章详情

@implementation CultureNetService

+ (void)getCultureMenuWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSDictionary *listDict))response
{
    [[GFXNetworkHandle shareHandle]post:CulturemenuUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableDictionary *listDict = [NSMutableDictionary dictionary];
            NSDictionary *containDict = json[@"result"];
            NSArray *titles = [containDict allKeys];
            for (NSInteger i=0; i<titles.count; i++) {
                NSMutableArray *arr = [NSMutableArray array];
                for (NSDictionary *dict in containDict[titles[i]]) {
                    MenuListModel *model = [MenuListModel objectWithDict:dict];
                    [arr addObject:model];
                }
                [listDict setValue:arr forKey:titles[i]];
            }
            response(YES,json[@"message"],listDict);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)articleListsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    [[GFXNetworkHandle shareHandle]post:ArticleListsUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                ArticleListModel *model = [ArticleListModel objectWithDict:dict];
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)articleDetailWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,ArticleListModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:ArticleDetailUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            ArticleListModel *model = [ArticleListModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

@end
